<?php
namespace Application\Component;
use Doctrine\ORM\EntityManager;
use Application\Entity\Location;
use DateTime;
use Application\Component\AbstractComponent;
/**
 * LocationServcie
 *
 */
class LocationComponent extends AbstractComponent
{
    protected  $entity="Application\\Entity\\Location";

 
	function insert($location)
	{
		$datetime = new DateTime("now");
		$location->createdAt = $datetime;
		$location->modifiedAt = $datetime;
		$this->em->persist($location);
		$this->em->flush();
	}
	
	
	function update($location)
	{
		$datetime = new DateTime("now");
		$location->modifiedAt = $datetime;
		$this->em->persist($location);
		$this->em->flush();
	}
	
	function get($uid)
	{
		$location = $this->em->find($this->entity, $uid);
		return  $location;
	}
	
	function getAll()
	{
		$location = $this->em->getRepository($this->entity)->findAll();
		return  $location;
	}
	
	function getByUid($uid)
	{
		$location = $this->em->getRepository($this->entity)->getByUid($uid);
		return  $location;
	}
	
	function getByParent($parent)
	{
		$location = $this->em->getRepository($this->entity)->getByParent($parent);
		return  $location;
	}
	

	
	function delete($id)
	{
		$location = $this->em->find($this->entity, $id);
		$this->em->remove($location);
		$this->em->flush();
	}
}
